package com.wsm.springai.studydemo2.gh;

import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class GhInfoService {


    // 将患者数据存储在类级别变量中，使其在多个请求间保持状态
    public static final ArrayList<QueryController.Patient> queryListInfo = new ArrayList<>();

    public GhInfoService() {
        // 初始化数据
        queryListInfo.add(new QueryController.Patient(1, "张三", "内科", "待就诊"));
        queryListInfo.add(new QueryController.Patient(2, "李四", "外科", "已缴费"));
        queryListInfo.add(new QueryController.Patient(3, "王五", "风湿科", "已退费"));
        queryListInfo.add(new QueryController.Patient(4, "赵六", "儿科", "待就诊"));
    }


    @Tool(description = "退号,必须提供id和姓名，只提供了一个的话，告诉用户需要在提供另一个，如果两个都提供了，提示用户是否确认退号，用户确认才可以执行")
    public String cancel(@ToolParam int id , @ToolParam String name) {
        for (int i = 0; i < queryListInfo.size(); i++) {
            QueryController.Patient patient = queryListInfo.get(i);
            if (patient.id() == id && patient.name().equals(name) ) {
                // 创建新的Patient对象，状态更新为"已退费"
                QueryController.Patient updatedPatient = new QueryController.Patient(
                        patient.id(),
                        patient.name(),
                        patient.department(),
                        "已退费"
                );
                queryListInfo.set(i, updatedPatient);
                break;
            }
        }
        return "退号成功";
    }
}
